package com.qf.test.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.qf.test.pojo.DtsOrder;
import com.qf.test.vo.CategorySellAmts;
import com.qf.test.vo.DayStatis;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 订单表 Mapper 接口
 * </p>
 *
 * @author zhaojian
 * @since 2021-05-12
 */
public interface DtsOrderMapper extends BaseMapper<DtsOrder> {
    /**
     * 统计最近多少天的订单的增长量和当天订单的总金额
     */
    @Select("SELECT DATE_FORMAT(a.add_time,'%Y-%m-%d') as dayStr, " +
            "COUNT(*) as cnts,SUM(actual_price) as amts " +
            "from dts_order a  " +
            "where a.deleted=0 " +
            "GROUP BY DATE_FORMAT(a.add_time,'%Y-%m-%d')")
    public List<DayStatis> staticsIncresOrederCnt();

    /**
     * 按照分类 统计每个分类中的商品的销售额、
     */
    @Select("SELECT d.`name`,SUM(a.price) as value " +
            "FROM dts_order_goods a " +
            "LEFT JOIN dts_order b on a.order_id=b.id " +
            "LEFT JOIN dts_goods c on a.goods_id=c.id " +
            "LEFT JOIN dts_category d on c.category_id=d.id " +
            "WHERE a.deleted=0 and b.deleted=0 and d.`name` is not NULL " +
            "GROUP BY d.`name`")

    public List<CategorySellAmts> categorySell();

    /**
     * 统计最近多少天内的用户增长量
     */
    @Select("SELECT DATE_FORMAT(a.add_time,'%Y-%m-%d') as dayStr,count(*) as cnts " +
            "from dts_user a " +
            "where a.deleted=0 " +
            "GROUP BY DATE_FORMAT(a.add_time,'%Y-%m-%d')")
    public List<DayStatis> staticIncreasuUser();

}
